#include "HelloWorldScene.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "deprecated/CCDeprecated.h"
#include "ui/UIHelper.h"
#include "base/CCConsole.h"

USING_NS_CC;

using namespace cocostudio::timeline;
using namespace ui;

Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
	log("@~~~~~~~~~~~~~~~~~~~~~~~~%d", time(0));
	auto rootNode = CSLoader::createNode("login.csb");
	
	ui::Button* tLoginB = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)rootNode, 93);
	tLoginB->addTouchEventListener(this, toucheventselector(HelloWorld::onLogin));
	tLoginB = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)rootNode, 94);
	tLoginB->addTouchEventListener(this, toucheventselector(HelloWorld::onLogin));
	const Vec2& tPos = tLoginB->getPosition();
	log("!~~~~~~~~~~~~~~~~~~~~~~~~%d", time(0));

    addChild(rootNode);

    return true;
}

void HelloWorld::onLogin(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type) {
	log("-------------------");
	auto rootNode = CSLoader::createNode("MainScene.csb");
    addChild(rootNode);
}